<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <link rel="stylesheet" href="./js/element-ui/index.css" />
    <script type="text/javascript" src="./js/vue.min.js"></script>
    <script type="text/javascript" src="./js/element-ui/index.js"></script>
    <script type="text/javascript" src="./js/vue-cropper.js"></script>
    <style>
        .cropper-wrap .cut {
            width: 100%;
            height: 300px;
            margin: 10px auto;
            text-align: center
        }

        .cropper-wrap .cut-btns {
            margin-top: 15px
        }

        .cropper-wrap .cut-btns .el-button {
            font-size: 14px
        }

        .cropper-wrap .cut-btns .el-button .iconfont {
            vertical-align: bottom;
            font-size: 14px
        }
        .result-panel{
            background: #f4f4f7;
        }
        .tx-item:hover .tx-info{
            color: #3c7ee5;
        }
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="Vue_root">
        <input class="file-input" id="file1" name="file1" type="file"
            accept="image/png, image/jpeg, image/gif, image/jpg" @change="changepic(this)" />
        <input id="imgSrc" value="" type="hidden" />

        <el-dialog title="图片上传" :visible.sync="imageUploadDialog" width="33%" top="5vh" center>
            <div class="cropper-wrap">
                <p class="cropper-notice">
                    想要得到更精准的结果，请裁掉多于文字、数字、字母等，只留下图形部分，再上传。
                </p>
                <div class="cut">
                    <vue-cropper ref="cropper" :img="option.img" :output-size="option.size"
                    :output-type="option.outputType" :info="true" :full="option.full" :can-move="option.canMove"
                    :can-move-box="option.canMoveBox" :fixed-box="option.fixedBox" :original="option.original"
                    :auto-crop="option.autoCrop" :auto-crop-width="option.autoCropWidth"
                    :auto-crop-height="option.autoCropHeight" :center-box="option.centerBox" :high="option.high"
                    @img-load="imgLoad">
                    </vue-cropper>
                </div>
                <div class="cut-btns text-center">
                    <el-button type="primary" circle @click="refreshCrop"><i class="el-icon-refresh"></i>
                    </el-button>
                    <el-button type="primary" circle @click="changeScale(1)"><i class="el-icon-zoom-in"></i>
                    </el-button>
                    <el-button type="primary" circle @click="changeScale(-1)"><i class="el-icon-zoom-out"></i>
                    </el-button>
                    <el-button type="primary" circle @click="rotateLeft"><i class="iconfont icon-turnleft"></i>
                    </el-button>
                </div>
            </div>
            <span slot="footer">
                <el-button @click="imageUploadDialog = false" v-if="false">使用原图</el-button>
                <!-- <el-button @click="startCrop">开始截图</el-button> -->
                <el-button type="primary" @click="finish">上 传</el-button>
            </span>
        </el-dialog>
    </div>
    <script type="text/javascript">
        //引入vue-cropper的js文件
        Vue.use(window['vue-cropper']);
      // Vue.use(window['vue-cropper'].default);
    </script>
    <script type="text/javascript">
        "use strict";
        new Vue({
            el: '#Vue_root',
            data: {
                imageUploadDialog: false, //图片裁剪
                option: {
                    img: '',
                    size: 1,
                    full: false,
                    outputType: 'png',
                    canMove: true,
                    fixedBox: false,
                    original: false,
                    canMoveBox: true,
                    autoCrop: true,
                    // 只有自动截图开启 宽度高度才生效
                    autoCropWidth: 200,
                    autoCropHeight: 150,
                    centerBox: false,
                    high: true
                },
                tuxing: {
                    cls: '',
                    imgSrc: '',
                    file1: ''
                }
            },
            create() {

            },
            methods: {
                imgLoad: function (msg) { },
                refreshCrop: function refreshCrop() {
                    this.$refs.cropper.refresh();
                },
                rotateLeft: function rotateLeft() {
                    this.$refs.cropper.rotateLeft();
                },
                changeScale: function changeScale(num) {
                    num = num || 1;
                    this.$refs.cropper.changeScale(num);
                },
                finish: function finish() {
                    // 输出
                    this.$refs.cropper.getCropData(function (data) {
                        // 不用通信了 _(:з」∠)_
                        // $('#imgSrc').val(data);
                        //  $('#imgShapefile').attr('src', data);
                        console.log("剪切后的上传图片:",data);
                    });
                    this.imageUploadDialog = false;
                },
                changepic: function (param) {
                    var that = this;
                    var reads = new FileReader();
                    var f = document.getElementById('file1').files[0];
                    reads.readAsDataURL(f);
                    reads.onload = function (e) {
                        that.tuxing.file1 = document.getElementById('file1').value;
                        that.tuxing.imgSrc = this.result;
                        //  document.getElementById('imgShapefile').src = this.result;
                        $('#imgSrc').val(this.result);
                        // 显示图片裁剪框
                        that.cropperDialog(this.result)
                    };
                },
                cropperDialog: function cropperDialog() {
                    this.option.img = $('#imgSrc').val();
                    this.imageUploadDialog = true;
                }
            }
        })
    </script>
    <script type="text/javascript">
        $(function () {
            console.log("我是谁=====");
        });
    </script>
</body>

</html>